﻿namespace Raven
{
    public abstract class TriggerRespawning<entity_type> : Trigger<entity_type>
    {
        //When a bot comes within this trigger's area of influence it is triggered
        //but then becomes inactive for a specified amount of time. These values
        //control the amount of time required to pass before the trigger becomes 
        //active once more.
        protected Fix _respawningTime;
        protected Fix _timeRemainingUntilRespawn;

        public TriggerRespawning(EntityType type) : base(type)
        {
            _respawningTime = 0;
            _timeRemainingUntilRespawn = 0;
        }

        //sets the trigger to be inactive for m_iNumUpdatesBetweenRespawns 
        //update-steps
        protected void Deactivate()
        {
            SetInactive();
            _timeRemainingUntilRespawn = _respawningTime;
        }


        public override void Update()
        {
            _timeRemainingUntilRespawn = _timeRemainingUntilRespawn - 1;
            if (_timeRemainingUntilRespawn <= 0 && !isActive())
            {
                SetActive();
            }
        }

        public void SetRespawnDelay(Fix respawningTime)
        {
            _respawningTime = respawningTime * Constants.FrameRate;
        }
    }
}